package com.ys.service.purchase.impl;

import com.alibaba.fastjson.JSON;
import com.ys.vo.R;
import com.ys.dto.AddDto;
import com.ys.entity.purchase.TcgDistribution;
import com.ys.mapper.purchase.TcgDistributionMapper;
import com.ys.service.purchase.TcgDistributionService;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @Author: fxz
 * @CreateTime: 2024-09-23
 * @Description: 1688铺货
 * @Version: 1.0
 */
@Service("tcgDistributionService")
public class TcgDistributionServiceImpl implements TcgDistributionService {

    private static final Logger logger = Logger.getLogger(TcgDistributionServiceImpl.class);

    @Autowired
    private TcgDistributionMapper tcgDistributionMapper;


    @Override
    public R edit(Map<String, Object> params) {

        TcgDistribution entity = JSON.parseObject(JSON.toJSONString(params), TcgDistribution.class);
        tcgDistributionMapper.update(entity);

        return R.ok(AddDto.gotoEdit("/web/purchase/tcgDistribution/toEdit?id=" + entity.getId()));
    }

    /**
     * 修改子件信息维护
     * @param params
     * @return
     */
    @Override
    @Transactional(timeout=120,propagation= Propagation.REQUIRES_NEW)
    public R editZj(Map<String, Object> params) {

        TcgDistribution entity = JSON.parseObject(JSON.toJSONString(params), TcgDistribution.class);
        //判断子件信息是否唯一
        if (new TcgDistribution().setScode(entity.getScode()).where("A.id != " + entity.getId()).count() != 0){
            return R.error("该子件信息已使用,请核实后再操作!");
        }
        tcgDistributionMapper.update(entity);

        return R.ok(AddDto.gotoEdit("/web/purchase/tcgDistribution/toEdit?id=" + entity.getId()));
    }

}
